package com.xiaozhi.service.impl;

import com.xiaozhi.dao.TPushSubMapper;
import com.xiaozhi.entity.TPushDevice;
import com.xiaozhi.entity.TPushQuestion;
import com.xiaozhi.entity.TPushSub;
import com.xiaozhi.service.ITPushDeviceService;
import com.xiaozhi.service.ITPushQuestionService;
import com.xiaozhi.service.ITPushSubService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 主题推送Service业务层处理
 *
 * @author zhaoyk
 * @date 2025-11-24
 */
@Service
public class TPushSubServiceImpl extends     BaseServiceImpl  implements ITPushSubService {
    @Autowired
    private TPushSubMapper tPushSubMapper;


    @Autowired
    private ITPushQuestionService pushQuestionService;


    @Autowired
    private ITPushDeviceService pushDeviceService;

    /**
     * 查询主题推送
     *
     * @param id 主题推送主键
     * @return 主题推送
     */
    @Override
    public TPushSub selectTPushSubById(String id) {
        return tPushSubMapper.selectTPushSubById(id);
    }

    /**
     * 查询主题推送列表
     *
     * @param tPushSub 主题推送
     * @return 主题推送
     */
    @Override
    public List<TPushSub> selectTPushSubList(TPushSub tPushSub) {
        List<TPushSub> tPushSubs = tPushSubMapper.selectTPushSubList(tPushSub);
        for (int i = 0; i < tPushSubs.size(); i++) {
            String id = tPushSubs.get(i).getId();
            TPushDevice tPushDevice = new TPushDevice();
            tPushDevice.setPushSubId(id);
            List<TPushDevice> tPushDevices = pushDeviceService.selectTPushDeviceList(tPushDevice);
            tPushSubs.get(i).setDeviceList(tPushDevices);
            // 问题信息
            TPushQuestion tPushQuestion = new TPushQuestion();
            tPushQuestion.setPushSubId(id);
            List<TPushQuestion> tPushQuestions = pushQuestionService.selectTPushQuestionList(tPushQuestion);
            tPushSubs.get(i).setQuestionList(tPushQuestions);
        }
        return tPushSubs;
    }

    /**
     * 新增主题推送
     *
     * @param tPushSub 主题推送
     * @return 结果
     */
    @Override
    public int insertTPushSub(TPushSub tPushSub) {



        return 1;
    }

    /**
     * 修改主题推送
     *
     * @param tPushSub 主题推送
     * @return 结果
     */
    @Override
    public int updateTPushSub(TPushSub tPushSub) {
        return 1;
    }

    /**
     * 批量删除主题推送
     *
     * @param ids 需要删除的主题推送主键
     * @return 结果
     */
    @Override
    public int deleteTPushSubByIds(String[] ids) {
        return tPushSubMapper.deleteTPushSubByIds(ids);
    }

    /**
     * 删除主题推送信息
     *
     * @param id 主题推送主键
     * @return 结果
     */
    @Override
    public int deleteTPushSubById(String id) {
        return tPushSubMapper.deleteTPushSubById(id);
    }
}
